home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / niftp / rtn_proc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  7.3 KB  |  341 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3.  
  4. /*
  5.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  6.  *
  7.  *
  8.  *     Copyright (C) 1979,1980,1981  University of Delaware
  9.  *
  10.  *     Department of Electrical Engineering
  11.  *     University of Delaware
  12.  *     Newark, Delaware  19711
  13.  *
  14.  *     Phone:  (302) 738-1163
  15.  *
  16.  *
  17.  *     This program module was developed as part of the University
  18.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  19.  *
  20.  *     Acquisition, use, and distribution of this module and its listings
  21.  *     are subject restricted to the terms of a license agreement.
  22.  *     Documents describing systems using this module must cite its source.
  23.  *
  24.  *     The above statements must be retained with all copies of this
  25.  *     program and may not be removed without the consent of the
  26.  *     University of Delaware.
  27.  *
  28.  *
  29.  *     version  -1    David H. Crocker    March   1979
  30.  *     version   0    David H. Crocker    April   1980
  31.  *     version  v7    David H. Crocker    May     1981
  32.  *     version   1    David H. Crocker    October 1981
  33.  *
  34.  */
  35. /* for channel Q NIFTP returning list of duff addresses to sender       */
  36. /*                                                                      */
  37. /*      Steve Kille     August 1982                                     */
  38.  
  39. #include "msg.h"
  40. #include "adr_queue.h"
  41.  
  42.  
  43. extern char *multcat();
  44. extern struct ll_struct *logptr;
  45.  
  46. extern char *supportaddr;        /* supoport address for mail messages */
  47. extern char *locfullname;
  48. #ifdef UCL_TSNAME
  49. extern char TSname[];
  50. #endif UCL_TSNAME
  51.  
  52. LOCVAR char rtn_sndel[] = "Failed mail";
  53.  
  54.  
  55. struct rtn_str
  56. {
  57.     struct rtn_str  *r_link;
  58.     char            *r_buf;
  59. };
  60.  
  61. LOCVAR struct rtn_str
  62.     *rtn_bad = (struct rtn_str *) 0,
  63.     *rtn_ok = (struct rtn_str *) 0;
  64. /* */
  65.  
  66. rtn_init ()
  67.                 /* clean up any debris                  */
  68. {
  69.     struct rtn_str *ptr;
  70.  
  71.     while (rtn_ok != 0)
  72.     {
  73.     ptr = rtn_ok;
  74.     free (ptr -> r_buf);
  75.     rtn_ok = rtn_ok -> r_link;
  76.     free ( (char *)ptr);
  77.     }
  78.  
  79.     while (rtn_bad != 0)
  80.     {
  81.     ptr = rtn_bad;
  82.     free (ptr -> r_buf);
  83.     rtn_bad = rtn_bad -> r_link;
  84.     free ( (char *)ptr);
  85.     }
  86. }
  87.  
  88. /* */
  89.  
  90. rtn_adr (adr, good)
  91. char    *adr;
  92. {
  93.     struct rtn_str *rptr;
  94.     extern char *malloc();
  95.  
  96. #ifdef DEBUG
  97.     ll_log (logptr, LLOGBTR, "rtn_adr (%s, %d)", adr, good);
  98. #endif
  99.  
  100.     rptr = (struct rtn_str *) malloc (sizeof (struct rtn_str));
  101.     if (rptr == (struct rtn_str *) 0)
  102.     return (RP_NO);
  103.  
  104.     rptr -> r_buf = multcat ("\t", adr, "\n", (char *)0);
  105.     if (rptr ->  r_buf == (char *) NOTOK)
  106.     return (RP_NO);
  107.  
  108.     if (good)
  109.     {
  110.     rptr -> r_link =  rtn_ok;
  111.     rtn_ok = rptr;
  112.     }
  113.     else
  114.     {
  115.     rptr -> r_link = rtn_bad;
  116.     rtn_bad = rptr;
  117.     }
  118.  
  119.     return (RP_OK);
  120. }
  121.  
  122.  
  123.  
  124. /* */
  125.  
  126. rtn_errmsg (sender, rtn_fp)     /* Fire of list ofbad addresses to sender */
  127. char    *sender;                /* sender of message                    */
  128. FILE    *rtn_fp;                /* pointer to message file              */
  129. {
  130.  
  131.     if (rtn_bad  == (struct rtn_str *) 0)    /* No error addresses built up */
  132.     return (OK);
  133.  
  134.  
  135. #ifdef DEBUG
  136.     ll_log (logptr, LLOGPTR, "rtn_errmsg (%s)", sender);
  137. #endif
  138.  
  139.                 /* If sender not specified              */
  140.                 /* generate default                     */
  141.                 /* May throw away later if this becomes */
  142.                 /* a problem                            */
  143.     if (sender[0] == '\0')
  144.     strcpy (sender, supportaddr);
  145.  
  146.     if (rtn_mlinit (rtn_sndel, sender) != OK)
  147.     return (NOTOK);           /* set up for returning               */
  148.  
  149.     rtn_nogood ();               /* give list of bad addresses     */
  150.  
  151. #ifdef CITATION
  152.     rtn_cite (rtn_fp, CITATION);
  153. #else
  154.     rtn_cite (rtn_fp, 500);
  155. #endif
  156.  
  157.     return (ml_end (OK));
  158. }
  159. /* */
  160.  
  161. rtn_ack (ackadr, rtn_fp)     /* Fire of list ofbad addresses to ackadr */
  162. char    *ackadr;                /* ackadr of message                    */
  163. FILE    *rtn_fp;                /* pointer to message file              */
  164. {
  165.  
  166.  
  167.  
  168. #ifdef DEBUG
  169.     ll_log (logptr, LLOGPTR, "rtn_ack (%s)", ackadr);
  170. #endif
  171.  
  172.                 /* If ackadr not specified              */
  173.                 /* generate default                     */
  174.                 /* May throw away later if this becomes */
  175.                 /* a problem                            */
  176.     if (ackadr == (char *) 0 || ackadr[0] == '\0')
  177.     return (OK);    /* no address to ack to */
  178.  
  179.     if (rtn_mlinit ("Message Acknowledgement", ackadr) != OK)
  180.     return (NOTOK);           /* set up for returning               */
  181.  
  182.     rtn_good ();
  183.     rtn_nogood ();
  184.  
  185.     rtn_cite (rtn_fp, 25);
  186.  
  187.     return (ml_end (OK));
  188. }
  189. /* */
  190.  
  191. LOCFUN
  192.     rtn_nogood ()
  193.             /*  handle bad addresses                        */
  194. {
  195.     struct rtn_str *ptr;
  196.  
  197.     if (rtn_bad == 0)
  198.     return;
  199.  
  200. #ifdef    UCL_TSNAME
  201.     if(*TSname == '+') {
  202.     ml_txt("\nWARNING: Cannot reverse translate: <");
  203.     ml_txt(TSname);
  204.     ml_txt("> from the NRS database\n");
  205.     }
  206. #endif    UCL_TSNAME
  207.     ml_txt ("\nYour message was not delivered to the following addresses: \n\n");
  208.  
  209.     for (ptr = rtn_bad; ptr != 0; ptr = ptr -> r_link) {
  210.     to80 (ptr -> r_buf);
  211.     ml_txt (ptr -> r_buf);
  212.     }
  213.  
  214.     ml_txt ("\n\n");
  215. }
  216.  
  217. to80(from)
  218. char *from;
  219. {
  220.     register char   *p;
  221.     char    *lastspace = NULL, *lastnl = from;
  222.  
  223.     for(p = from ; *p ; p++){
  224.         if(*p != ' ' && *p != '\t')
  225.             continue;
  226.         if( p - lastnl > 80){
  227.             if(lastspace != NULL){
  228.                 *lastspace = '\n';
  229.                 lastnl = lastspace;
  230.                 if(p - lastnl <= 80){
  231.                      lastspace = p;
  232.                     continue;
  233.                 }
  234.             }
  235.             lastspace = NULL;
  236.             *p = '\n';
  237.             lastnl = p;
  238.             continue;
  239.         }
  240.         lastspace = p;
  241.     }
  242.     if(p - lastnl > 80 && lastspace != NULL)
  243.         *lastspace = '\n';
  244. }
  245.  
  246. LOCFUN
  247.     rtn_good ()
  248.             /* handle good addresses for ack        */
  249. {
  250.     struct rtn_str *ptr;
  251.  
  252.     if (rtn_ok == 0)
  253.     return;
  254.  
  255.     ml_txt ("\nYour message was accepted by: ");
  256.     ml_txt (locfullname);
  257.     ml_txt ("\n    for delivery to the following addresses:\n\n");
  258.  
  259.     for (ptr = rtn_ok; ptr != 0; ptr = ptr -> r_link) {
  260.     to80 (ptr -> r_buf);
  261.     ml_txt (ptr -> r_buf);
  262.     }
  263.  
  264.     ml_txt ("\n\n");
  265. }
  266.  
  267.  
  268. /* */
  269.  
  270. LOCFUN
  271.     rtn_mlinit (subject, sender)
  272. char    subject[];
  273. char    sender[];
  274. {
  275.     extern char *sitesignature;
  276.  
  277. #ifdef DEBUG
  278.     ll_log (logptr, LLOGBTR, "rtn_mlinit (%s)", subject);
  279. #endif
  280.  
  281.     if (isnull (sender[0]))     /* no return address                  */
  282.     {
  283.     ll_log (logptr, LLOGTMP, "no return address");
  284.     return (NOTOK);
  285.     }
  286.     if (ml_1adr (NO, NO, sitesignature, subject, sender) != OK)
  287.     {                             /* no return, no Sender:              */
  288.     ll_err (logptr, LLOGTMP, "ml_1adr");
  289.     return (NOTOK);
  290.     }
  291.     return (OK);
  292. }
  293. /* */
  294.  
  295. rtn_cite (rtn_fp, count)
  296. FILE    *rtn_fp;
  297. int     count;
  298. {
  299.     short     lines;
  300.     char    linebuf[LINESIZE];
  301.  
  302. #ifdef DEBUG
  303.     ll_log (logptr, LLOGBTR, "rtn_cite ()");
  304. #endif
  305.  
  306.     ml_txt ("\n    Your message begins as follows:\n\n");
  307.  
  308.     rewind (rtn_fp);
  309.  
  310.                 /* Skip JNT mail header                 */
  311.     while (fgets (linebuf, sizeof linebuf, rtn_fp) != NULL)
  312.     {
  313.     if (linebuf[0] == '\n')
  314.         break;
  315.     }
  316.  
  317.     while (fgets (linebuf, sizeof linebuf, rtn_fp) != NULL)
  318.     {
  319.     ml_txt (linebuf);         /* do headers                           */
  320.     if (linebuf[0] == '\n')
  321.         break;
  322.     }
  323.  
  324.     if (ferror (rtn_fp))
  325.     err_abrt (RP_FIO, "Error reading text for return-to-msg_sender.");
  326.  
  327.     if (!feof (rtn_fp))
  328.     {
  329.     for (lines = count; --lines > 0 &&
  330.         fgets (linebuf, sizeof linebuf, rtn_fp) != NULL;)
  331.     {
  332.         if (linebuf[0] == '\n')
  333.         lines++;          /* truly blank lines don't count      */
  334.         ml_txt (linebuf);
  335.     }
  336.     if (!feof (rtn_fp))       /* if more, give an elipses           */
  337.         ml_txt ("...\n");
  338.     }
  339. }
  340.  
  341.